﻿<%@ include file="/common/validate.jsp"%>
<%!
	public static Message getToken(Input input) {
		Integer hospital = input.getInt("hospital");
		Integer type = input.getInt("type", 0);
		Message message = new Message();
		// 数据库查询
		List list = QBuilder.db("basedb").queryHql("from access_token where hospital = " + hospital + " and type= " + type + " order by create_time desc");
		if (list.size() == 0) {
			// 没有匹配的记录
			message.setErrcode(20004);
			return message;
		}
		// 取出数据库中acccess_token记录
		Map tokenMap = (HashMap) list.get(0);
		int expireIn = 1000 * (Tools.getInt(tokenMap.get("expire_in") + "", 0) );
		Long createAt = Tools.getLong(tokenMap.get("create_time") + "", 0L);
		Long now = System.currentTimeMillis();
		if (now > (createAt + expireIn)) {
			// 过期
			message.setErrcode(20002);
			return message;
		}
		message.setErrmsg("token验证成功");
		message.put("access_token", (String)tokenMap.get("access_token"));
		message.put("expire_in", tokenMap.get("expire_in") + "");
		return message;
	}
%>
<%
	Tools.encryptPrint(out, getToken(input));
%>